#! /bin/bash

Bus=`lsusb | grep "22cd" | awk '{print $2}'`
Device=`lsusb | grep "22cd" | awk '{print substr($4,0,4)}'`

if [ -z "${Bus}" ] || [ -z "${Device}" ]
        then echo -e "\e[31mDevice not found"
        else
        {
                sudo chmod 777 /dev/bus/usb/"$Bus"/"$Device"
                if (echo $# >> /dev/null)
                        then echo -e "\e[32mDevice connected"
                        else echo -e "\e[31mError during connection"
                fi
        }
fi

echo -e "\e[0m\c"
